Vue.component("Report", {
    template:'<div class="alert alert-input-upload-form show report">'+
    '<div class="over-close"></div><div class="box"><div class="reportHeader flexItem between borderBtm"><div>举报</div><img @click="closeReport" class="closeReport" src="images/close1.png"></div>'+    
    '<ul class="form" style="margin-top:25px;"><li><div class="tt">举报原因</div><select v-model="typeId" id=""><option :key="index" :value="item.id" v-for="(item,index) in list">{{item.name}}</option></select></li><li><div class="tt">企业介绍</div><textarea v-model="reason" name="" placeholder="请简要描述举报原因" id="" cols="30" rows="10"></textarea></li><li><div class="tt">证据截图</div>'+
    '<div class="flexItem"><div class="itemImg" v-for="(item,index) in uploadImg" :key="index"><img class="closeImg" src="images/close_icon.png" @click="delImg(index)"/><img class="upImg" :src="getImgUrl(item)" /></div><div class="upload itemImg" v-if="uploadImg.length<9"><span>上传照片({{uploadImg.length}}/9)</span><input type="file" name="" @change="uploadOImg($event)"></div></div>'+
    '</li></ul><div class="operate"><a @click="sureBtn" class="btn">确定</a></div></div></div>',
    prop:['type','id',"show"],  //type为1是举报公司，2是举报职位
    data:function(){
        return {
            list:[],
            reportId:GetRequest().id || "",
            uploadImg:[],
            reason:'',
            typeId:''
        }
        
    },
    mounted:function() {
        var vm = this
        indexprepare(function(data){
            if(this.type==1){
                vm.list = data.enterprise_report_type
            }else{
                vm.list = data.recruit_report_type
            }
        })
    },
    methods:{
        uploadOImg:function(e){
            uploadImg({
                file: e.target.files[0],
                success: successFn.bind(this),
                fail: failFn.bind(this)
            })
            function successFn(res) {
                this.cover = qiniuUrl + res.key
                this.uploadImg.push(res.key)
            }

            function failFn(err) {

            }
        },
        getImgUrl(key){
            return qiniuUrl+ '/' + key
        },
        delImg(index){
            this.uploadImg.splice(index,1)
        },
        sureBtn(){
            var url,params={
                id:this.reportId,  //公司或职位id
                type:this.typeId,
                content:this.reason,
                image:this.uploadImg
            },vm=this
            if(this.type==1){
                url="person/enterprise/report"
            }else{
                url="person/recruit/report"
            }
            request(url, 'POST', JSON.stringify(params), function (res) {
                vm.$message.success(res.message);
                vm.closeReport()
              }, function (err) {
                vm.$message.error(err.responseJSON.message);
            })
        },
        closeReport(){

            this.$emit('update:show', false);
        }

    }
})